package Staff

import (
	"ali-hr/Services/Staff"
	"ali-hr/Util"
	"github.com/gin-gonic/gin"
	"github.com/gookit/goutil/dump"
	"strconv"
)

/**
 * Created by Goland
 * User: wkk alisleepy@hotmail.com
 * Time: 2021/12/21 - 00:25
 * Desc: <员工相关controller>
 */

// List 员工列表
func List(c *gin.Context) {
	// 当前页
	pageIndex, _ := strconv.Atoi(c.PostForm("pageIndex"))
	// 每页条数
	pageSize, _ := strconv.Atoi(c.PostForm("pageSize"))
	// 搜索条件
	name := c.PostForm("name")
	departmentId, _ := strconv.Atoi(c.PostForm("department_id"))
	leaderId, _ := strconv.Atoi(c.PostForm("leader_id"))
	status := c.PostForm("status")
	jobNo := c.PostForm("job_no")

	// 组装filter
	filters := make(map[string]interface{})
	filters["name"] = name
	filters["department_id"] = departmentId
	filters["leader_id"] = leaderId
	filters["status"] = status
	filters["job_no"] = jobNo

	// 获取数据
	data, total, err := Staff.UserList(pageIndex, pageSize, filters, false)
	if err != nil {
		if Util.Debug() {
			dump.P("获取员工失败，err信息：", err)
		}
		Util.FailWithMessage("获取员工失败", c)
		return
	}
	result := make(map[string]interface{})
	result["data"] = data
	result["total"] = total
	Util.OkWithData(result, c)
}

// All 所哟员工
func All(c *gin.Context) {
	dump.P("获取所有员工。。。")
	staffs := Staff.AllStaffs()
	Util.OkWithData(staffs, c)
}

// Info 查看员工基本信息
func Info(c *gin.Context) {

}

// UpdateStaff 修改员工信息
func UpdateStaff(c *gin.Context) {

}

// DeleteStaff 禁用员工账号
func DeleteStaff(c *gin.Context) {

}

// Resign 员工离职操作，修改雇佣状态信息
func Resign(c *gin.Context) {

}

// ExportStaff 导出员工资料信息
func ExportStaff(c *gin.Context) {

}
